#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN=1050;
int v[MAXN];
int dp[MAXN];
int main(void){
    int n;
    while(~scanf("%d",&n)){
        if(0==n){
            break;
        }
        for(int i=0;i<n;i++){
            scanf("%d",&v[i]);
        }
        int m;
        scanf("%d",&m);
        if(m<5){
            printf("%d\n",m);
            continue;
        }
        m-=5;
        sort(v,v+n);
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n-1;i++){
            for(int j=m;j>=0;j--){
                if(j>=v[i]){
                    dp[j]=max(dp[j],dp[j-v[i]]+v[i]);
                }
            }
        }
        printf("%d\n",m+5-dp[m]-v[n-1]);
    }
    return 0;
}